/**
 * Created by luyon on 2017/8/23.
 */

"use strict";

import React from "react" ;
import {browserHistory} from 'react-router';
// import V from "../../../../../static/img/film/geren-V.png";
import V from "../../../../../static/img/h5/V-geren.png";
import qiyeV from "../../../../../static/img/h5/V-qiye.png";
import tx from "../../../../../static/img/film/moren-tx.png";

import NetworkEngine from "../../../../../utils/NetworkEngine" ;
import UrlManager from "../../../../../utils/UrlManager" ;

class FilmCommentHuifuContainer extends React.Component {

    constructor(p) {
        super(p);
        this.state = {
            time: "",
            btnId: "",
            modelId: "",
            userId: "",
            replyUserId: ""
        }
    }

    componentWillMount() {
        // let newTime = this.props.time.substring(0, this.props.time.indexOf("."));
        // let model = this.props.replyUserId;
        // let btnId = "id"+this.props.id
        // this.setState({
        //     time: newTime,
        //     btnId:btnId,
        //     modelId:model
        // })
        // let userId = sessionStorage.getItem("id");
        // userId = userId.substring(userId.length-32,userId.length);
        // let replyUserId = this.props.replyUserId;
        // replyUserId = replyUserId.substring(replyUserId.length-32,replyUserId.length);
        // this.setState({
        //
        //     userId:userId,
        //     replyUserId:replyUserId
        // })
    }

    //删除和回复弹框显示
    showModal_1() {
        let id = "#rep_" + this.props.id;
        $(id).show();
        $(".closeModal").click(function () {
            $(".footer-up").hide();
        })
    }

    deleteReply() {
        sessionStorage.setItem("deleteStatus", "huifu");
        sessionStorage.setItem("deleteId", this.props.id);
        // $("#cancel_model").show()
        let urlManager = new UrlManager();
        NetworkEngine(
            "post",
            urlManager.deleteReply(), {
                "replyId": this.props.id,
                "userId": sessionStorage.getItem("id"),
                userKeyId: sessionStorage.getItem("userKeyId")
            },
        ).then(
            data => {
                if (data.data.status == "0") {
                    this.props.getNewReply();
                }
            }
        ).catch(
            err => {

            }
        )
    }

    frashHuifu() {
        this.props.getNewReply();
    }

    reply() {
        // alert(this.props.replyUserId+"  "+ this.props.commentId+" "+this.props.replyUserName)
        return this.props.replyReply(this.props.replyUserId, this.props.commentId, this.props.replyUserName)
    }

    //进入个人主页
    queryCreator() {
        // e.preventDefault();
        localStorage.setItem("personalId", this.props.replyUserId)

        browserHistory.push("/App/MobileMine/");
        window.scrollTo(0, 0);
    }

    render() {

        var content = {
            __html:this.props.content
        };

        let Logo = () => {
            if (this.props.status == 1) {
                if (this.props.type == "0") {
                    return <img src={V} alt="图标"/>
                } else {
                    return <img src={qiyeV} alt="图标"/>
                }
            } else {
                return <span></span>

            }

        };
        return (
            <ul className="writer-huifu">
                <div style={{display: "none"}}>
                    <span id={this.state.btnId} onClick={this.frashHuifu.bind(this)}>获取</span>
                </div>
                <li className="clearfix">
                    <div className="writer-img">
                        <img src={this.props.headUrl ? this.props.headUrl : tx} alt="作者头像"
                             onClick={this.queryCreator.bind(this)}/>
                    </div>
                    <ul className="writer-p">
                        <li className="p1">
                            {this.props.replyUserName}
                            <Logo/>
                            <span>{this.props.time}</span>
                        </li>
                        {
                            sessionStorage.getItem("id")
                                ?
                                <li className="p3" onClick={this.showModal_1.bind(this)} dangerouslySetInnerHTML={content}></li>
                                :
                                <li className="p3" dangerouslySetInnerHTML={content}></li>
                        }
                        <div className="footer-up" id={"rep_" + this.props.id}>
                            <div className="p-parent">
                                <p className="closeModal">
                                    {
                                        this.props.session == "" || this.props.session == null ? <span></span> : <span>
                                         {this.props.replyUserId == this.props.session ?
                                             <a className="del" onClick={this.deleteReply.bind(this)}>删除</a> :
                                             <a className="del" onClick={this.reply.bind(this)}>回复</a>}

                                    </span>
                                    }
                                </p>
                                <p className="closeModal">取消</p>
                            </div>
                        </div>
                    </ul>
                </li>
            </ul>

        )
    }
}

export {FilmCommentHuifuContainer as default} ;